﻿package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.system.Security;
	import flash.utils.ByteArray;
	
	import game.controller.LoginCenter;
	import game.managers.ConfigManager;
	import game.managers.LanguageManager;
	import game.managers.LayerManager;
	import game.managers.PopManage;
	import game.managers.StageManager;
	import game.managers.StageProxy;
	import game.utils.Utils;
	import game.view.scene.GameView;

	[SWF(width="950", height="600", frameRate="30")]
	public class GameStarter extends Sprite
	{
		[Embed(source="languageList.txt", mimeType="application/octet-stream")]
		private var _textdata:Class;

		public function GameStarter()
		{
			super();

			//跨脚本访问
				Security.allowDomain("*");
			//检测是否已经被添加到舞台上
			if (stage)
			{
				init();
			}
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(evt:Event=null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			stage.stageFocusRect=false;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			stage.align=StageAlign.TOP_LEFT;

			//注册舞台
			StageProxy.registed(stage);
			//初始化舞台
			StageManager.getInstance().init(stage);
			//初始化层
			var game:GameView=GameView.getInstance();
			addChild(game);
			
			/**是否连接服务器,若为false则使用默认数据*/
			ConfigManager.CONNECT_SERVER = false;
						
			PopManage.layer=LayerManager.windowLayer;

			loadTextData();

			LoginCenter.getInstance().showLoadingView();
			
		}

	


		private function loadTextData():void
		{
			var byteArray:ByteArray=new _textdata() as ByteArray;
			var str:String=byteArray.readUTFBytes(byteArray.length);
			LanguageManager.setup(str);
		}
	}

}